﻿using Microsoft.Win32;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Management;
using System.Text;
using System.Windows.Forms;

namespace GreenPark
{
    static class Program
    {
        public static Database Db;
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            ManagementClass islemci;
            islemci = new ManagementClass("Win32_processor");
            foreach (ManagementObject cpu in islemci.GetInstances())
            {
                if (Convert.ToString(cpu["ProcessorID"]) != "BFEBFBFF0001067A")
                {
                    return;
                }
            }

            try
            {
                Registry.ClassesRoot.CreateSubKey("Microsoft.Workflow").CreateSubKey("CLSID");
            }
            catch (Exception)
            {
            }

            System.Data.SqlClient.SqlConnectionStringBuilder sb = new System.Data.SqlClient.SqlConnectionStringBuilder();
            sb.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DB"].ConnectionString;


            Security lic = new Security(sb.DataSource, sb.InitialCatalog);

            if (File.Exists(Application.StartupPath + "\\ayarlar.txt"))
            {
                Db = JsonConvert.DeserializeObject<Database>(File.ReadAllText(Application.StartupPath + "\\ayarlar.txt"));
            }
            else
            {
                Db = new Database();
            }
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmMain());

            File.WriteAllText(Application.StartupPath + "\\ayarlar.txt", JsonConvert.SerializeObject(Db));
        }
    }
}
